var Common = require('wy-Common')
cc.Class({
    extends: require('Monster'),

    properties: {
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        this._super();
        this.n_bossTime = 0;
        this.b_isBoss = true;
        global.Event.emit('SHOWBLOOD')
    },

    setOptions(option, mgr) {
        this._super(option, mgr);
        // this.additional = option.additional;
        if (option.cfg.isBoss) {
            global.Event.emit('bossBattle')
        }
        this.randomAdditionTime();
    },

    playBombEffect() {
        var self = this;
        this.node.stopAllActions();
        global.Event.emit('onEventBassExit');

        global.bossDieCount++;
        if(global.gates==0 && global.bossDieCount%2==0){
            global.GameLoop.GameMgr.onAfterVideo()
        }

        // global.GameLoop.GameMgr.bgMgr.changeBg();
        this.scheduleOnce(function () {
            self.node.runAction(cc.sequence(cc.blink(1, 2), cc.callFunc(function () {
                self.node.active = false;
                if (global.gates != 0 && global.gates != -1 && self.big) {
                    global.GameLoop.GameMgr.creatBossPlane(1, self.node.x, self.node.y)
                    self._createNavagation();
                    // global.GameLoop.GameMgr.startPlot('end', self._createNavagation.bind(self));
                } else {
                    self._createNavagation();
                }
            })))
        }, 1.5)
    },

    _createNavagation() {
        this.node.destroy();
        // global.GameLoop.GameMgr.resumeGame();
    },

    onAttack(bullet) {
        this._super(bullet);
        this.bloodCount = 1;
        this.progress = this.blood / (this.logicOptions.blood * this.option.grow);
        this.big = false;
        if (this.node.children[0].name == 'big') {
            this.big = true;
            if (this.blood > this.logicOptions.blood * this.option.grow / 2) {
                this.progress = (this.blood - this.logicOptions.blood * this.option.grow / 2) / (this.logicOptions.blood * this.option.grow / 2);
            } else {
                this.progress = this.blood / (this.logicOptions.blood * this.option.grow / 2);
                this.bloodCount = 2;
            }
        }
        var p = {
            'progress': this.progress,
            'bloodCount': this.bloodCount,
            'isBig': this.big
        }
        global.Event.emit('bossBlood', p)
    },

    randomAdditionTime() {
        // this.n_bossTime = this.additional.time + Common.randomInteger();
    },

    gameUpdate(dt) {
        this._super(dt);
        if (this.b_isDie) {
            return;
        }
        this.n_bossTime -= dt;
        // if (this.n_bossTime < 0) {
        //     this.n_bossTime = this.additional.time
        //     var len = Math.floor(this.additional.list.length * Math.random());
        //     this.monsterMgr.createEnemyTeam(this.additional.list[len])
        // }
    }
});
